package com.smart.village.big.screen.controller.bigscreen;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.smart.village.big.screen.domain.*;
import com.smart.village.big.screen.service.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import static com.smart.village.big.screen.domain.AjaxResult.error;
import static com.smart.village.big.screen.domain.AjaxResult.success;

/**
 * 党组织情况
 */
@Tag(name = "党组织情况接口")
@RestController
@RequestMapping("/party/organization")
public class PartyOrganizationController {
    Logger logger = Logger.getLogger(PartyOrganizationController.class.getName());

    @Autowired
    private PartyOrganizationService partyOrganizationService;
    @Autowired
    private PartyOrganizationTenureService partyOrganizationTenureService;
    @Autowired
    private PartyOrganizationActivityService partyOrganizationActivityService;
    @Autowired
    private PartyFeesService partyFeesService;
    @Autowired
    private PartyOrganizationApplicationService partyOrganizationApplicationService;
    @Autowired
    private PartyMemberInformationService partyMemberInformationService;

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    /**
     * 获取大屏 组织建设主模块 组织生活
     *
     * @param formatDate
     * @return
     */
    @Operation(summary = "获取大屏 组织建设主模块 组织生活，查询支部下面的活动 根据不同的月份 YYYY-MM 和 党组织编号 获取三会一课列表和指标")
    @Parameters({
            @Parameter(name = "formatDate", description = "格式化的时间月份 YYYY-MM"),
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委")
    })
    @GetMapping("/activity/getOrganizationLifeList")
    @ResponseBody
    public AjaxResult getOrganizationLifeList(@RequestParam(required = false) String formatDate,
                                              @RequestParam(required = false) String partyOrganizationSerialNumber) {
        try {
            if (StringUtils.isEmpty(formatDate)) {
                formatDate = DateFormatUtils.format(new Date(), "yyyy-MM");
            }
            // 从redis中获取数据
            String key = "partyOrganizationActivityList:" + formatDate + ":" + partyOrganizationSerialNumber;
            JSONObject result = (JSONObject) redisTemplate.opsForValue().get(key);
            if (!ObjectUtils.isEmpty(result)) {
                return success( result );
            } else {
                List<String> activityTypeList = Lists.newArrayList();
                activityTypeList.add("党员大会");
                activityTypeList.add("党小组会");
                activityTypeList.add("支委会");
                activityTypeList.add("党课");
                activityTypeList.add("主题党日");

                JSONObject resultJson = partyOrganizationActivityService.getPartyOrganizationActivityList(formatDate, partyOrganizationSerialNumber, activityTypeList, "支部");
                // 缓存数据
                redisTemplate.opsForValue().set(key, resultJson, 3, TimeUnit.HOURS);
                return success(resultJson);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 组织建设主模块 民主生活会
     *
     * @param formatDate
     * @return
     */
    @Operation(summary = "获取大屏 组织建设主模块 民主生活会，查询支部下面的活动 根据不同的月份 YYYY-MM 和 党组织编号 获取三会一课列表和指标")
    @Parameters({
            @Parameter(name = "formatDate", description = "格式化的时间月份 YYYY-MM"),
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委")
    })
    @GetMapping("/activity/getDemocraticLifeAssociationList")
    @ResponseBody
    public AjaxResult getDemocraticLifeAssociationList(@RequestParam(required = false) String formatDate,
                                                       @RequestParam(required = false) String partyOrganizationSerialNumber) {
        try {
            List<String> activityTypeList = Lists.newArrayList();
            activityTypeList.add("民主生活会");
            if (StringUtils.isEmpty(formatDate)) {
                formatDate = DateFormatUtils.format(new Date(), "yyyy-MM");
            }
            return success(partyOrganizationActivityService.getPartyOrganizationActivityList(formatDate, partyOrganizationSerialNumber, activityTypeList, "支部"));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 组织建设主模块  活动 文件详情
     *
     * @return
     */
    @Operation(summary = "获取大屏 组织建设主模块 活动 文件详情")
    @Parameters({
            @Parameter(name = "partyOrganizationActivitySerialNumber", description = "活动主键")
    })
    @GetMapping("/activity/getPartyOrganizationActivitiesUploadDetail")
    @ResponseBody
    public AjaxResult getPartyOrganizationActivitiesUploadDetail(
            @RequestParam String partyOrganizationActivitySerialNumber) {
        try {
            return success(partyOrganizationActivityService.getPartyOrganizationActivitiesUploadDetail(partyOrganizationActivitySerialNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }


    /**
     * 获取大屏 组织建设主模块 组织生活会
     *
     * @param formatDate
     * @return
     */
    @Operation(summary = "获取大屏 组织建设主模块 组织生活会，查询支部下面的活动 根据不同的月份 YYYY-MM 和 党组织编号 获取三会一课列表和指标")
    @Parameters({
            @Parameter(name = "formatDate", description = "格式化的时间月份 YYYY-MM"),
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委")
    })
    @GetMapping("/activity/getOrganizationLifeAssociationList")
    @ResponseBody
    public AjaxResult getOrganizationLifeAssociationList(@RequestParam(required = false) String formatDate,
                                                         @RequestParam(required = false) String partyOrganizationSerialNumber) {
        try {
            List<String> activityTypeList = Lists.newArrayList();
            activityTypeList.add("组织生活会");
            if (StringUtils.isEmpty(formatDate)) {
                formatDate = DateFormatUtils.format(new Date(), "yyyy-MM");
            }
            return success(partyOrganizationActivityService.getPartyOrganizationActivityList(formatDate, partyOrganizationSerialNumber, activityTypeList, "支部"));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 组织建设 党组情况 三个指标
     *
     * @return
     */
    @Operation(summary = "获取大屏 组织建设 党组情况 三个指标")
    @Parameters({
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委")
    })
    @GetMapping("getThreeQuota")
    @ResponseBody
    public AjaxResult getThreeQuota(
            @RequestParam(required = false, defaultValue = "") String partyOrganizationSerialNumber) {
        try {
            JSONObject resultJson = partyOrganizationService.getThreeQuota(partyOrganizationSerialNumber);
            return success(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 组织建设 换届补选 列表
     *
     * @return
     */
    @Operation(summary = "获取大屏 组织建设 换届补选 列表")
    @Parameters({
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委")
    })
    @GetMapping("getPartyOrganizationTenure")
    @ResponseBody
    public AjaxResult getPartyOrganizationTenure(
            @RequestParam(required = false, defaultValue = "") String partyOrganizationSerialNumber) {
        try {
            JSONObject resultJson = partyOrganizationTenureService.getPartyOrganizationTenure(partyOrganizationSerialNumber);
            return success(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    @Operation(summary = "获取大屏 组织建设 换届补选 详情")
    @Parameters({
            @Parameter(name = "tenureSerialNumber", description = "换届补选的序列号")
    })
    @GetMapping("getPartyOrganizationTenureDetail")
    @ResponseBody
    public AjaxResult getPartyOrganizationTenureDetail(
            @RequestParam String tenureSerialNumber) {
        try {
            JSONObject resultJson = partyOrganizationTenureService.getPartyOrganizationTenureDetail(tenureSerialNumber);
            return success(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 组织建设 党费收缴情况 按照 年月
     *
     * @return
     */
    @Operation(summary = "获取大屏 组织建设 党费收缴情况 按照 年月")
    @Parameters({
            @Parameter(name = "formatDate", description = "格式化的时间月份 YYYY-MM"),
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委")
    })
    @GetMapping("getPartyFeesStatistics")
    @ResponseBody
    public AjaxResult getPartyFeesStatistics(
            @RequestParam(required = false, defaultValue = "") String partyOrganizationSerialNumber,
            @RequestParam(required = false, defaultValue = "") String formatDate
    ) {
        try {
            PartyFeesStatisticsVo partyFeesStatisticsVo = new PartyFeesStatisticsVo();
            if (StringUtils.isEmpty(formatDate)) {
                String format = DateFormatUtils.format(new Date(), "yyyy-MM");
                partyFeesStatisticsVo.setYearMonthStr(format);
            } else {
                partyFeesStatisticsVo.setYearMonthStr(formatDate);
            }
            partyFeesStatisticsVo.setPartyOrganizationSerialNumber(partyOrganizationSerialNumber);
            return success(partyFeesService.getPartyFeesStatistics(partyFeesStatisticsVo));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 组织建设 党费收缴情况 按照 年月
     *
     * @return
     */
    @Operation(summary = "获取大屏 组织建设 党费收缴情况 详情列表")
    @Parameters({
            @Parameter(name = "formatDate", description = "格式化的时间月份 YYYY-MM"),
            @Parameter(name = "partyOrganizationSerialNumber", description = "单层级党组织序列号")
    })
    @GetMapping("getPartyFeesStatisticsDetail")
    @ResponseBody
    public AjaxResult getPartyFeesStatisticsDetail(
            @RequestParam String partyOrganizationSerialNumber,
            @RequestParam(required = false, defaultValue = "") String formatDate
    ) {
        try {
            PartyFeesStatisticsVo partyFeesStatisticsVo = new PartyFeesStatisticsVo();
            if (StringUtils.isEmpty(formatDate)) {
                String format = DateFormatUtils.format(new Date(), "yyyy-MM");
                partyFeesStatisticsVo.setYearMonthStr(format);
            } else {
                partyFeesStatisticsVo.setYearMonthStr(formatDate);
            }
            partyFeesStatisticsVo.setPartyOrganizationSerialNumber(partyOrganizationSerialNumber);
            return success(partyFeesService.getPartyFeesStatisticsDetail(partyFeesStatisticsVo));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 组织建设 党员队伍管理 列表
     *
     * @return
     */
    @Operation(summary = "获取大屏 组织建设 党员队伍管理 第一层五个指标")
    @Parameters({
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委")
    })
    @GetMapping("getPartyOrganizationApplicationStatic")
    @ResponseBody
    public AjaxResult getPartyOrganizationApplicationStatic(
            @RequestParam(required = false, defaultValue = "") String partyOrganizationSerialNumber
    ) {
        try {
            JSONObject partyOrganizationApplicationStatic = partyOrganizationApplicationService.getPartyOrganizationApplicationStatic(partyOrganizationSerialNumber);
            return success(partyOrganizationApplicationStatic);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 组织建设 党员队伍管理 列表
     *
     * @return
     */
    @Operation(summary = "获取大屏 组织建设 党员队伍管理 列表")
    @Parameters({
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委"),
            @Parameter(name = "type", description = "1-申请人，2-积极分子，3-发展对象，4-预备党员，5-正式党员")
    })
    @GetMapping("getPartyOrganizationApplication")
    @ResponseBody
    public AjaxResult getPartyOrganizationApplication(
            @RequestParam(required = false, defaultValue = "") String partyOrganizationSerialNumber,
            @RequestParam(required = false, defaultValue = "") String type

    ) {
        try {
            List<PartyOrganizationApplicationStaticVo> resultJson =
                    partyOrganizationApplicationService.getPartyOrganizationApplication(partyOrganizationSerialNumber, type);
            return success(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 组织建设 党员队伍 申请详情
     *
     * @return
     */
    @Operation(summary = "获取大屏 组织建设 党员队伍管理 详情")
    @Parameters({
            @Parameter(name = "applicationSerialNumber", description = "党员申请的序列号")
    })
    @GetMapping("getPartyMemberLogStaticDetail")
    @ResponseBody
    public AjaxResult getPartyMemberLogStaticDetail(
            @RequestParam String applicationSerialNumber) {
        try {
            List<PartyMemberLogStaticVo> resultJson = partyOrganizationApplicationService.getPartyMemberLogStaticDetail(applicationSerialNumber);
            return success(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 组织建设 各领域党员分析
     *
     * @return
     */
    @Operation(summary = "获取大屏 组织建设 各领域党员分析")
    @Parameters({
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委")
    })
    @GetMapping("getPartyMemberStatic")
    @ResponseBody
    public AjaxResult getPartyMemberStatic(
            @RequestParam(required = false, defaultValue = "") String partyOrganizationSerialNumber) {
        try {
            List<List<JSONObject>> resultJsonList = partyMemberInformationService.getPartyMemberStatic(partyOrganizationSerialNumber);
            return success(resultJsonList);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 组织建设 各领域党员分析 详情
     *
     * @return
     */
    @Operation(summary = "获取大屏 组织建设 各领域党员分析 详情")
    @Parameters({
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委")
    })
    @GetMapping("getPartyMemberStaticDetail")
    @ResponseBody
    public AjaxResult getPartyMemberStaticDetail(
            @RequestParam(required = false, defaultValue = "") String partyOrganizationSerialNumber) {
        try {
            JSONObject resultJson = new JSONObject();

            List<HashMap<String, Object>> partyMemberStaticDetail = partyMemberInformationService.getPartyMemberStaticDetail(partyOrganizationSerialNumber);
            resultJson.put("partyMemberStaticDetail", partyMemberStaticDetail);

            List<List<JSONObject>> partyMemberStatic = partyMemberInformationService.getPartyMemberStatic(partyOrganizationSerialNumber);
            resultJson.put("partyMemberStatic", partyMemberStatic);
            return success(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 党建工作预警监督指标-换届选举、主题党日、党费缴纳
     *
     * @param formatDate
     * @return
     */
    @Operation(summary = "获取大屏 党建工作预警监督指标")
    @Parameters({
            @Parameter(name = "formatDate", description = "格式化的时间月份 YYYY-MM"),
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委")
    })
    @GetMapping("/getPartyConstructionEarlyWarning")
    @ResponseBody
    public AjaxResult getPartyConstructionEarlyWarning(@RequestParam(required = false) String formatDate,
                                                       @RequestParam(required = false, defaultValue = "") String partyOrganizationSerialNumber) {
        try {
            if (StringUtils.isEmpty(formatDate)) {
                formatDate = DateFormatUtils.format(new Date(), "yyyy-MM");
            }
            // 从redis中获取数据
            String key = "getPartyConstructionEarlyWarning:" + formatDate + ":" + partyOrganizationSerialNumber;
            List<List<JSONObject>> result = (List<List<JSONObject>>) redisTemplate.opsForValue().get(key);
            if (!ObjectUtils.isEmpty(result)) {
                return success( result );
            } else {

                List<List<JSONObject>> resultJsonList = new ArrayList<>();

                // 组织生活的指标
                List<String> activityTypeList = Lists.newArrayList();
                activityTypeList.add("党员大会");
                activityTypeList.add("党小组会");
                activityTypeList.add("支委会");
                activityTypeList.add("党课");
                activityTypeList.add("主题党日");
                JSONObject partyOrganizationActivityJSON = partyOrganizationActivityService.getPartyOrganizationActivityList(formatDate, partyOrganizationSerialNumber, activityTypeList, "支部");
                List<JSONObject> activityList = Lists.newArrayList();

                JSONObject plan = new JSONObject();
                plan.put("total", partyOrganizationActivityJSON.get("should"));
                plan.put("text", "筹备");
                plan.put("value", partyOrganizationActivityJSON.get("plan"));
                activityList.add(plan);

                JSONObject started = new JSONObject();
                started.put("total", partyOrganizationActivityJSON.get("should"));
                started.put("text", "已完成");
                started.put("value", partyOrganizationActivityJSON.get("started"));
                activityList.add(started);

                JSONObject notStarted = new JSONObject();
                notStarted.put("total", partyOrganizationActivityJSON.get("should"));
                notStarted.put("text", "未完成");
                notStarted.put("value", partyOrganizationActivityJSON.get("notStarted"));
                activityList.add(notStarted);
                resultJsonList.add(activityList);

                // 换届选举的指标
                JSONObject partyOrganizationTenureJson = partyOrganizationTenureService.getPartyOrganizationTenure(partyOrganizationSerialNumber);

                List<JSONObject> tenureList = Lists.newArrayList();
                JSONObject finish = new JSONObject();
                finish.put("total", partyOrganizationTenureJson.get("total"));
                finish.put("value", partyOrganizationTenureJson.get("finish"));
                finish.put("text", "已完成");
                tenureList.add(finish);
                JSONObject unfinished = new JSONObject();
                unfinished.put("total", partyOrganizationTenureJson.get("total"));
                unfinished.put("value", partyOrganizationTenureJson.get("unfinished"));
                unfinished.put("text", "未完成");
                tenureList.add(unfinished);
                JSONObject preparing = new JSONObject();
                preparing.put("total", partyOrganizationTenureJson.get("total"));
                preparing.put("value", partyOrganizationTenureJson.get("preparing"));
                preparing.put("text", "筹备");
                tenureList.add(preparing);
                JSONObject will = new JSONObject();
                will.put("total", partyOrganizationTenureJson.get("total"));
                will.put("value", partyOrganizationTenureJson.get("will"));
                will.put("text", "应开展");
                tenureList.add(will);
                resultJsonList.add(tenureList);

                //党员缴费的指标
                PartyFeesStatisticsVo partyFeesStatisticsVo = new PartyFeesStatisticsVo();
                if (StringUtils.isEmpty(formatDate)) {
                    String format = DateFormatUtils.format(new Date(), "yyyy-MM");
                    partyFeesStatisticsVo.setYearMonthStr(format);
                } else {
                    partyFeesStatisticsVo.setYearMonthStr(formatDate);
                }
                partyFeesStatisticsVo.setPartyOrganizationSerialNumber(partyOrganizationSerialNumber);
                List<PartyFeesStatisticsVo> partyFeesStatistics = partyFeesService.getPartyFeesStatistics(partyFeesStatisticsVo);
                int totalCnt = 0;
                int feeCnt = 0;
                int willCnt = 0;
                for (PartyFeesStatisticsVo partyFeesStatistic : partyFeesStatistics) {
                    totalCnt += partyFeesStatistic.getTotalCnt();
                    feeCnt += partyFeesStatistic.getFeeCnt();
                    willCnt += partyFeesStatistic.getWillCnt();
                }

                List<JSONObject> feeList = Lists.newArrayList();


                JSONObject feeJson = new JSONObject();
                feeJson.put("total", totalCnt);
                feeJson.put("value", feeCnt);
                feeJson.put("text", "已缴纳");
                feeList.add(feeJson);

                JSONObject willJson = new JSONObject();
                willJson.put("total", totalCnt);
                willJson.put("value", willCnt);
                willJson.put("text", "未缴纳");
                feeList.add(willJson);
                resultJsonList.add(feeList);
                // 缓存数据
                redisTemplate.opsForValue().set(key, resultJsonList, 3, TimeUnit.HOURS);
                return success(resultJsonList);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 基层治理 双联系双报道 列表和指标
     *
     * @param formatDate
     * @return
     */
    @Operation(summary = "获取大屏 基层治理 双联系双报道 列表和指标")
    @Parameters({
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委")
    })
    @GetMapping("/activity/getTwoContactTwoReport")
    @ResponseBody
    public AjaxResult getTwoContactTwoReport(@RequestParam(required = false) String formatDate,
                                             @RequestParam(required = false) String partyOrganizationSerialNumber) {
        try {
            List<String> activityTypeList = Lists.newArrayList();
            activityTypeList.add("双联系双报到");
            if (StringUtils.isEmpty(formatDate)) {
                formatDate = DateFormatUtils.format(new Date(), "yyyy-MM");
            }
            return success(partyOrganizationActivityService.getTwoContactTwoReport(formatDate, partyOrganizationSerialNumber, activityTypeList));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 基层治理 预警监督
     *
     * @return
     */
    @Operation(summary = "获取大屏 基层治理 预警监督")
    @Parameters({
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委")
    })
    @GetMapping("/activity/getEarlyWarning")
    @ResponseBody
    public AjaxResult getEarlyWarning(
            @RequestParam(required = false) String formatDate,
            @RequestParam(required = false, defaultValue = "") String partyOrganizationSerialNumber) {
        try {
            List<String> activityTypeList = Lists.newArrayList();
            activityTypeList.add("双联系双报到");
            if (StringUtils.isEmpty(formatDate)) {
                formatDate = DateFormatUtils.format(new Date(), "yyyy-MM");
            }
            JSONObject resultJsonList = partyOrganizationActivityService.getEarlyWarning(formatDate, partyOrganizationSerialNumber, activityTypeList);
            return success(resultJsonList);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 组织建设 精品研学路线
     *
     * @return
     */
    @Operation(summary = "获取大屏 组织建设 精品研学路线")
    @GetMapping("/studyRoutes")
    @ResponseBody
    public AjaxResult studyRoutes() {
        try {
            List<BluePlateStudyRoutes> studyRoutes = partyOrganizationService.getAllBluePlateStudyRoutes();
            return success(studyRoutes);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 组织建设 精品研学路线详情
     *
     * @return
     */
    @Operation(summary = "获取大屏 组织建设 精品研学路线详情")
    @Parameters({
            @Parameter(name = "studyRouteSerialNumber", description = "研学路线序列号")
    })
    @GetMapping("/studyRoutesDetail")
    @ResponseBody
    public AjaxResult studyRoutesDetail(
            @RequestParam(required = false, defaultValue = "") String studyRouteSerialNumber) {
        try {
            List<StudyRoutesVo> studyRoutes = partyOrganizationService.studyRoutes(studyRouteSerialNumber);
            return success(studyRoutes);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 组织建设 省级基层党建示范点
     *
     * @return
     */
    @Operation(summary = "获取大屏 组织建设 省级基层党建示范点")
    @Parameters({
            @Parameter(name = "tagSerialNumber", description = "图例标签编码"),
            @Parameter(name = "villageSerialNumber", description = "镇编码"),
    })
    @GetMapping("/demonstrationSite")
    @ResponseBody
    public AjaxResult demonstrationSite(
            @RequestParam(required = false, defaultValue = "") String tagSerialNumber,
            @RequestParam String villageSerialNumber
    ) {
        try {
            List<StudyRoutesVo> studyRoutes = partyOrganizationService.demonstrationSite(tagSerialNumber, villageSerialNumber);
            return success(studyRoutes);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    @Operation(summary = "获取大屏 所有政府结构")
    @Parameters({

    })
    @GetMapping("getAllGovernmentStructure")
    @ResponseBody
    public AjaxResult getAllGovernmentStructure(  @RequestParam(required = false, defaultValue = "") String townNumber,
                                                  @RequestParam(required = false, defaultValue = "") String villageNumber){


        try {
            return success(partyOrganizationTenureService.getAllGovernmentStructure(townNumber, villageNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    @Operation(summary = "获取大屏 党建-教育培训 友情链接 最新的10条数据")
    @GetMapping("/getFriendShipLinks")
    @ResponseBody
    public AjaxResult getFriendShipLinks(
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        try {
            if (ObjectUtils.isEmpty(pageNum) || pageNum == 0) {
                pageNum = 1;
            }
            if (ObjectUtils.isEmpty(pageSize) || pageSize == 0) {
                pageSize = 10;
            }
            return success(partyOrganizationService.getFriendShipLinks( pageNum, pageSize));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }
}
